fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 #21554#2434
fix(p2p/discover): avoid dropping unverified nodes when table is almost empty #21396 #21554#2434gzliudan wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a7d1594 to
81fa248
Compare
81fa248 to
3aa7566
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors Discovery v4 UDP handling by extracting the wire-level packet codec/types into a dedicated p2p/discover/v4wire package and adjusts lookup/findnode behavior to avoid prematurely dropping (unverified) nodes when the routing table is sparse.
Changes:
- Introduces
p2p/discover/v4wire(packet types + encode/decode + EIP-8 vectors) and updates UDPv4 to use it. - Updates FINDNODE/NEIGHBORS handling: avoid surfacing unverified nodes when verified ones exist, but still return unverified when the table has no verified nodes; also avoids returning a timeout if at least one NEIGHBORS reply arrived.
- Adjusts lookup failure-drop behavior to only drop a node after repeated failures when its bucket isn’t close to empty; adds/updates tests (including small-net convergence).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| p2p/discover/v4wire/v4wire.go | Adds Discovery v4 wire packet types and codec (encode/decode, pubkey helpers, constants). |
| p2p/discover/v4wire/v4wire_test.go | Adds EIP-8 forward-compatibility decoding vectors for the new wire package. |
| p2p/discover/v4_udp.go | Switches UDPv4 to v4wire packets/codec and updates FINDNODE/NEIGHBORS handling and matcher behavior. |
| p2p/discover/v4_udp_test.go | Updates UDPv4 tests for v4wire and adds a small localhost network convergence test. |
| p2p/discover/v4_lookup_test.go | Updates lookup tests to use v4wire packet types. |
| p2p/discover/table.go | Replaces closest with findnodeByID (prefer-live semantics) and adds bucketLen. |
| p2p/discover/table_test.go | Updates table tests to cover findnodeByID. |
| p2p/discover/node.go | Removes now-relocated node key recovery helper. |
| p2p/discover/lookup.go | Avoids dropping nodes on repeated empty FINDNODE results when their bucket is too small. |
…thereum#21147 This moves all v4 protocol definitions to a new package, p2p/discover/v4wire. The new package will be used for low-level protocol tests.
…st empty ethereum#21396 ethereum#21554 This change improves discovery behavior in small networks. Very small networks would often fail to bootstrap because all member nodes were dropping table content due to findnode failure. The check is now changed to avoid dropping nodes on findnode failure when their bucket is almost empty. It also relaxes the liveness check requirement for FINDNODE/v4 response nodes, returning unverified nodes as results when there aren't any verified nodes yet. The "findnode failed" log now reports whether the node was dropped instead of the number of results. The value of the "results" was always zero by definition. Co-authored-by: Felix Lange <fjl@twurst.com>
3aa7566 to
a6ba7ee
Compare
Proposed changes
Ref:
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that